import { Component } from 'react';
import InputCom from '../../components/content/comment/InputCom';
import ListCom from '../../components/content/comment/ListCom';
import './Comment.scss';
class Comment extends Component {
  state = {
    listArr: [{ critic: 'Jay', content: '七里香' }],
  };
  // 删除评论
  delReview = (index) => {
    if (window.confirm('确定要删除当前评论吗？')) {
      this.setState({
        // 过滤掉下标相等的评论
        listArr: this.state.listArr.filter((i, TAG) => index !== TAG),
      });
    }
  };
  // 添加评论至列表
  addData = (data) => {
    this.setState({
      listArr: [...this.state.listArr, data],
    });
  };
  render() {
    return (
      <>
        <div className="comment">
          {/* 输入评论人和内容 */}
          <InputCom addData={this.addData} />
          {/* 列表 */}
          <ListCom listArr={this.state.listArr} delReview={this.delReview} />
        </div>
      </>
    );
  }
}

export default Comment;
